import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            imports: ['vue'],
            // Auto import functions from Element Plus, e.g. ElMessage, ElMessageBox... (with style)
            // 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
    server: {
        host: '0.0.0.0',
        // port: env.VITE_PORT as unknown as number,
        // open: env.VITE_OPEN,
        // proxy: {
        //   '/gitee': {
        //     target: 'https://gitee.com',
        //     ws: true,
        //     changeOrigin: true,
        //     rewrite: (path) => path.replace(/^\/gitee/, ''),
        //   }
        // },
        proxy: {
            '/dev-api': {
                target: `http://localhost:8848`,
                ws: true,
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/dev-api/, ''),
            },
        },
    },
    resolve: {
        alias: [
            {
                find: '@',
                replacement: path.resolve('./src'),
            },
        ],
    },
})
